home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
- 18: THE KEYBOARD 249
- --------------------------
-
- AMOS Basic provides you with dozens of useful keyboard commands. These
- can be used in anything from an Arcade game to an Adventure. It's even
- possible to write a fully fledged wordprocessor entirely in AMOS Basic!
-
-
-
- =INKEY$ (function to get a keypress)
-
- k$=INKEY$
-
- This function checks whether the user has pressed a key, and returns
- its value in the string k$
-
- Note the INKEY$ command doesn't wait your input in any way. If the
- user hasn't entered a character, INKEY$ will simply return an empty
- string "".
-
- INKEY$ is only capable of reading keys which return a specific Ascii
- character from the keyboard. Ascii is a standard code used to represent
- all the characters which can be printed on the screen.
-
- It's important to realise that some keys, like HELP button or the
- function keys, use a rather different format. If INKEY$ detects such a
- key, it will return a character with a value of zero (CHR$(0)). You can
- now find the internal scan code of this key using a separate SCAN CODE
- function.
-
-
-
- =SCANCODE (input the scancode of the last
- key input with INKEY$)
-
- s=SCANCODE
-
- SCANCODE returns the internal scancode of a key which has previously
- entered using the INKEY$ function. This allows you to check for keys
- which do not produce a character from the keyboard, such as HELP or
- TAB. Type the following small example:
-
- Do
- While K$=""
- K$=Inkey$
- Wend
- If Asc(K$)=0 Then Print "You pressed a key with no ASCII Code"
- Print "The Scancode Is";Scancode
- K$=""
- Loop
-
-
- =KEY STATE (test whether an individual 250
- key has been pressed)
-
- t=KEY STATE(s)
-
- Check if a specific button has been pressed on the Amiga's keyboard. s
- is the internal scancode of the key you want to check. If this key is
- currently being depressed then KEY state will return a value of true
- (-1), otherwise the result will be false (0).
-
-
-
- =KEY SHIFT (return the status of
- the shift keys)
-
- keys=KEY SHIFT
-
- KEY SHIFT returns the current status of the various control keys. These
- keys such as SHIFT or Alt cannot be detected using the standard INKY$
- or SCANCODE system. But you can easily test for any combination of
- control keys with just a single call to the KEY SHIFT function. "keys"
- is a bit map in the following format:
-
- Bit Key Tested Notes
- --- ---------- -----
- 0 Left SHIFT
- 1 Right SHIFT
- 2 Caps Lock Either ON or OFF
- 3 CTRL
- 4 Left ALT
- 5 Right ALT
- 6 Left AMIGA C= key on some keyboards
- 7 Right AMIGA
-
- If a bit is set to a one, then the associated button has been held down
- by the user.
-
-
-
- INPUT$(n) (function to input n
- characters into a string)
-
- INPUT$ enters n characters straight from the keyboard, waiting for each
- one in turn. As with INKEY$, these characters are not echoed onto the
- screen.
-
- x$ is a string variable which will be loaded with your new
- characters. n holds the number of characters to be entered. Example:
-
- Clear Key : Print "Type In Then Characters"
- C$=INPUT$(10) : Print "You entered ";C$
-
- This insturction *not* the same as the standard INPUT command. The two
- instuctions are completely different. Also note that there's a special
- version of INPUT$ which can be used to read your characters from the
- disc.
-
-
-
- WAIT KEY(wait for a keypress) 251
-
- WAIT KEY
-
- Waits for a single keypress.
-
-
-
- KEY SPEED (change key repeat speed)
-
- KEY SPEED lag,speed
-
- KEY SPEED lets you tailor the speed of the keyboard to your own
- particular taste. The new speed will be used for every part of the AMOS
- system, including the editor.
-
- "lag" is the time in 50th of a second between pressing a key, and the
- start of the repeat sequence.
-
- "speed" is the delay of second between each successive character.
-
-
-
- CLEAR KEY (initialise keyboard buffer)
-
- CLEAR KEY
-
- Whwnever you enter a character from the keyboard, its Ascii code is
- placed in an area of memory known as the keyboard buffer. It is this
- buffer that is sampled by the INKEY$ function to get your key presses.
-
- CLEAR key erases this buffer completely, and returns your keyboard to
- this original state. It's especially helpful at the start of a program,
- as the buffer may well be full of unwanted information. You can also
- call it immediately before a WAIT KEY comand to ensure that the program
- waits for a fresh keypress before preceding.
-
-
-
- PUT KEY (Put a string into the keyboard buffer) 252
-
- PUT KEY a$
-
- Loads a string a characters directly into the keyboard buffer. Carriage
- returns can be included using a CHR$(13) character.
-
- The most common use of PUT KEY is to set up defaults for your input
- routines. Here's a demonstration:
-
- Do
- Put Key "No"
- Input "Another Game";A$
- If A$="No" Then Exit
- Loop
-
-
-
- Input/Output
- ============
-
- INPUT (load a value from the user and
- put it a variable)
-
- INPUT
-
- Provides you with a standard way of entering information into one or
- more variables. There are two possible formats for this instrucion:
-
- INPUT vars[;]
-
- Enters a list of variables directly from the keyboard. "var" can
- contain any set of variables you like, separated by commas. A question
- mark will be automatically displayed at the current cursor position.
-
- INPUT "Prompt";variable list[;]
-
- Prints out the "prompt" string before entering your information. Note
- that you must always place a semi-colon between your text and the
- variable list. You are *not* allowed to use a comma for this purpose.
-
- The optional semi-colon ";" at the end of your variable list
- specifies that the text cursor will not be affected by the INPUT
- instruction, and will retain its original position after the data has
- been entered.
-
- When you execute one of these commands, Basic will wait for you enter
- the required information from the keyboard. Each variable in your list
- must be matched by a single value from the user. These values must be
- of the same as your original values, and should be separated by commas.
-
-
-
- LINE INPUT (input a list of 253
- variables separated by a Return)
-
- LINE INPUT "Prompt";variable list[;]
-
- Line input is exactly same as INPUT, except that it uses a Return
- instead of a comma to separate each value you enter from the keyboard.
-
-
-
-
-